<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:in="http://java.sun.com/jsf/composite/inward">



    <ui:define name="content">       

        <h:panelGroup rendered="true" styleClass="opdPanel" >
            <h:form id="form">
                <p:panel>
                    <f:facet name="header">
                        <h:outputLabel value="Total Value : "/>
                        <h:outputLabel value="#{surgeryBillController.batchBill.total}"/>
                        <p:commandButton value="Clear All" ajax="false"
                                        action="#{surgeryBillController.makeNull}"
                                         style="float: right;"/>
                        <p:commandButton value="Save Surgery Detail" ajax="false" 
                                        action="#{surgeryBillController.save()}" 
                                         style="float: right;" 
                                         disabled="#{surgeryBillController.batchBill.patientEncounter.paymentFinalized}"/>


                    </f:facet>

                    <p:panel> 
                        <f:facet name="header">
                            <h:outputLabel value="Sergery &amp; BHT Detail"/>
                        </f:facet>
                        <h:panelGrid columns="2">
                            <p:panel>
                                <h:outputLabel value="Type Patient Name or BHT : "/>
                                <p:autoComplete  forceSelection="true" converter="admis"
                                                 value="#{surgeryBillController.batchBill.patientEncounter}" 
                                                 completeMethod="#{admissionController.completePatient}"
                                                 var="apt2" itemLabel="#{apt2.patient.person.name}"
                                                 itemValue="#{apt2}" size="30"  style="width: 400px;">
                                    <p:ajax event="itemSelect"  update="panSearch2"  process="@this" />
                                    <p:column >
                                        #{apt2.bhtNo} 
                                    </p:column>
                                    <p:column >
                                        #{apt2.patient.person.name} 
                                    </p:column>
                                    <p:column>
                                        <h:outputLabel value="#{apt2.currentPatientRoom.roomFacilityCharge.name}"/>
                                    </p:column>
                                </p:autoComplete>
                                <h:panelGroup id="panSearch2">
                                    <in:bhtDetail admission="#{surgeryBillController.batchBill.patientEncounter}"/>
                                </h:panelGroup>
                            </p:panel>
                            <p:panel>
                                <p:panelGrid columns="2" >
                                    <h:outputLabel value="Surgery Name" >
                                    </h:outputLabel>
                                    <p:autoComplete forceSelection="true"
                                                    value="#{surgeryBillController.batchBill.procedure.item}" 
                                                    completeMethod="#{procedureController.completeDiagnosis}"
                                                    var="apt2" itemLabel="#{apt2.name}"
                                                    itemValue="#{apt2}" size="30"  style="width: 400px;">
                                    </p:autoComplete>
                                    <!--                                    <h:outputLabel value="Start Time" >
                                                                        </h:outputLabel>
                                                                        <p:calendar value="#{surgeryBillController.batchBill.procedure.fromTime}" pattern="dd MMMM yyyy hh mm a">
                                                                        </p:calendar>
                                                                        <h:outputLabel value="End Time" >
                                                                        </h:outputLabel>
                                                                        <p:calendar value="#{surgeryBillController.batchBill.procedure.toTime}" pattern="dd MMMM yyyy hh mm a" >
                                                                        </p:calendar>-->

                                </p:panelGrid>
                            </p:panel>
                        </h:panelGrid>
                    </p:panel>

                    <p:tabView >
                        <p:tab title="Professional Fee">
                            <p:panel>
                                <f:facet name="header">
                                    <h:panelGroup rendered="#{surgeryBillController.professionalBill.id ne null}">
                                        <h:panelGrid columns="2">
                                            <h:outputLabel value="Bill No  : "/>
                                            <h:outputLabel value="#{surgeryBillController.professionalBill.deptId}"/>
                                            <h:outputLabel value="Bill Total  : "/>
                                            <h:outputLabel value="#{surgeryBillController.professionalBill.total}"/>
                                        </h:panelGrid>
                                    </h:panelGroup>

                                </f:facet>
                                <h:panelGrid columns="2">
                                    <p:panel>
                                        <p:panelGrid columns="2" id="profPanel">
                                            <h:outputLabel value="Perfomance"/>
                                            <p:selectOneMenu  value="#{surgeryBillController.proEncounterComponent.patientEncounterComponentType}" >
                                                <f:selectItem itemLabel="Please select Perfomance"/>
                                                <f:selectItems value="#{enumController.patientEncounterComponentTypes}"/>
                                            </p:selectOneMenu>
                                            <h:outputLabel value="Discreption"/>
                                            <p:inputText autocomplete="off" id="txtDes" value="#{surgeryBillController.proEncounterComponent.description}" ></p:inputText>

                                            <h:outputText value="Speciality"/>
                                            <p:autoComplete converter="specilityCon"  forceSelection="true" id="cmbSpe" 
                                                            value="#{surgeryBillController.proEncounterComponent.billFee.speciality}" 
                                                            completeMethod="#{specialityController.completeSpeciality}" var="sp" 
                                                            itemLabel="#{sp.name}" 
                                                            itemValue="#{sp}" size="30"  style="width: 400px;">
                                                <f:ajax execute="cmbSpe" render="cmbDoc" event="select"/>
                                            </p:autoComplete>


                                            <h:outputText value="Doctor/Staff"/>
                                            <p:autoComplete converter="stfcon"  forceSelection="true" id="cmbDoc" 
                                                            value="#{surgeryBillController.proEncounterComponent.billFee.staff}" 
                                                            completeMethod="#{staffController.completeItems}" var="st" 
                                                            itemLabel="#{st.person.nameWithTitle}" itemValue="#{st}" size="30" 
                                                            style="width: 400px;">
                                                <f:ajax execute="cmbSpe" event="keypress"/>
                                            </p:autoComplete>

                                            <h:outputLabel value="Fee"/>
                                            <p:inputText autocomplete="off" id="prof" value="#{surgeryBillController.proEncounterComponent.billFee.feeValue}"/>
                                            <p:commandButton ajax="false" update="surgery"  
                                                             value="Add Professional Fee"  
                                                            action="#{surgeryBillController.addProfessionalFee()}"
                                                             disabled="#{surgeryBillController.batchBill.patientEncounter.paymentFinalized}"/>
                                        </p:panelGrid>
                                    </p:panel>
                                    <p:panel>
                                        <p:dataTable value="#{surgeryBillController.proEncounterComponents}" id="surgery"   var="c" >
                                            <p:column>
                                                <h:outputLabel value="#{c.patientEncounterComponentType}"></h:outputLabel>
                                            </p:column>
                                            <p:column>
                                                <h:outputLabel value="#{c.billFee.staff.person.nameWithTitle}"></h:outputLabel>
                                            </p:column>
                                            <p:column>
                                                <p:inputText autocomplete="off" value="#{c.billFee.feeValue}" disabled="#{c.billFee.paidValue!=0}" />
                                            </p:column>
                                            <p:column >
                                                <h:outputLabel value="#{c.billFee.createdAt}">
                                                    <f:convertDateTime pattern="dd MM yyyy"/>
                                                </h:outputLabel>                                                   
                                                <br/>
                                                <h:panelGroup rendered="#{c.billFee.retired}" >
                                                    <h:outputLabel style="color: red;" value="Deleted at " />
                                                    <h:outputLabel style="color: red;"  value="#{c.billFee.retiredAt}" >
                                                        <f:convertDateTime pattern="dd MMM yyyy"/>
                                                    </h:outputLabel>
                                                </h:panelGroup>
                                            </p:column>
                                            <p:column >
                                                <h:outputLabel value="#{c.billFee.creater.webUserPerson.name}"/>     
                                                <br/>
                                                <h:panelGroup rendered="#{c.billFee.retired}" >
                                                    <h:outputLabel style="color: red;" value="Deleted By " />
                                                    <h:outputLabel style="color: red;"  value="#{c.billFee.retirer.webUserPerson.name}" >                                       
                                                    </h:outputLabel>
                                                </h:panelGroup>
                                            </p:column>     
                                            <p:column headerText="Update">
                                                <p:commandButton ajax="false" value="Update"  
                                                                action="#{surgeryBillController.updateProFee(c.billFee)}"
                                                                 disabled="#{c.billFee.id eq null or surgeryBillController.batchBill.patientEncounter.paymentFinalized}"/>
                                            </p:column>

                                            <p:column headerText="Remove">
                                                <p:commandButton ajax="false" value="Remove"  
                                                                 rendered="#{c.billFee.id eq null}"
                                                                action="#{surgeryBillController.removeProEncFromList(c)}"
                                                                 disabled="#{surgeryBillController.batchBill.patientEncounter.paymentFinalized}"/>
                                                <p:commandButton ajax="false" value="Remove"  
                                                                 rendered="#{c.billFee.id ne null}"
                                                                action="#{surgeryBillController.removeProEncFromDbase(c)}"
                                                                 disabled="#{surgeryBillController.batchBill.patientEncounter.paymentFinalized}"/>
                                            </p:column>
                                        </p:dataTable>
                                    </p:panel>

                                </h:panelGrid>
                            </p:panel>                    
                        </p:tab>

                        <p:tab title="Timed Service">
                            <p:panel>
                                <f:facet name="header">                                
                                    <h:panelGroup rendered="#{surgeryBillController.timedServiceBill.id ne null}">
                                        <h:panelGrid columns="2">
                                            <h:outputLabel value="Bill No  : "/>
                                            <h:outputLabel value="#{surgeryBillController.timedServiceBill.deptId}"/>
                                            <h:outputLabel value="Bill Total  : "/>
                                            <h:outputLabel value="#{surgeryBillController.timedServiceBill.total}"/>
                                        </h:panelGrid>
                                    </h:panelGroup>
                                </f:facet>
                                <h:panelGrid columns="2">
                                    <p:panel>
                                        <p:panel id='pIxAdd' header="Timed Service Requests" style="min-height: 100px;"  >

                                            <p:autoComplete  forceSelection="false" 
                                                             value="#{surgeryBillController.timedEncounterComponent.billFee.patientItem.item}"
                                                             completeMethod="#{timedItemController.completeInvest}" var="ix" 
                                                             itemLabel="#{ix.name}" itemValue="#{ix}" size="30"  style="width: 400px;">
                                                <p:ajax event="itemSelect" process="@this" update="pDetail"/>
                                            </p:autoComplete>

                                        </p:panel>

                                        <p:panel header="Timed Item Detail" id="pDetail" >
                                            <h:panelGrid columns="2">
                                                <p:outputLabel value="Name :"/>
                                                <p:outputLabel value="#{surgeryBillController.timedEncounterComponent.billFee.patientItem.item.name}"/>

                                                <p:outputLabel value="StartTime:"/>
                                                <p:calendar id="startTime"  value="#{surgeryBillController.timedEncounterComponent.billFee.patientItem.fromTime}" 
                                                            pattern="dd MMMM yyyy hh mm a" >
                                                    <f:ajax event="dateSelect" execute="pDetail" />
                                                </p:calendar>                                                                      


                                            </h:panelGrid>   
                                            <p:commandButton value="Add Time Service" ajax="false"
                                                            action="#{surgeryBillController.addTimedService()}"
                                                             disabled="#{surgeryBillController.batchBill.patientEncounter.paymentFinalized}"/>
                                        </p:panel>
                                    </p:panel>
                                    <p:panel>
                                        <p:dataTable value="#{surgeryBillController.timedEncounterComponents}" var="ti">
                                            <p:column headerText="Service Name">
                                                #{ti.billFee.patientItem.item.name}
                                            </p:column>
                                            <p:column headerText="Start Time">
                                                <p:calendar navigator="true"  
                                                            value="#{ti.billFee.patientItem.fromTime}" 
                                                            pattern="dd MMMM yyyy hh mm a" />                                      
                                            </p:column>                               
                                            <p:column headerText="Stopped Time">
                                                <p:calendar navigator="true"  
                                                            value="#{ti.billFee.patientItem.toTime}" 
                                                            pattern="dd MMMM yyyy hh mm a" />  
                                            </p:column>
                                            <p:column headerText="Total">
                                                #{ti.billFee.patientItem.serviceValue}
                                            </p:column>
                                            <p:column >
                                                <h:outputLabel value="#{ti.billFee.createdAt}">
                                                    <f:convertDateTime pattern="dd MM yyyy"/>
                                                </h:outputLabel>                                                   
                                                <br/>
                                                <h:panelGroup rendered="#{ti.billFee.retired}" >
                                                    <h:outputLabel style="color: red;" value="Deleted at " />
                                                    <h:outputLabel style="color: red;"  value="#{ti.billFee.retiredAt}" >
                                                        <f:convertDateTime pattern="dd MMM yyyy"/>
                                                    </h:outputLabel>
                                                </h:panelGroup>
                                            </p:column>
                                            <p:column >
                                                <h:outputLabel value="#{ti.billFee.creater.webUserPerson.name}"/>     
                                                <br/>
                                                <h:panelGroup rendered="#{ti.billFee.retired}" >
                                                    <h:outputLabel style="color: red;" value="Deleted By " />
                                                    <h:outputLabel style="color: red;"  value="#{ti.billFee.retirer.webUserPerson.name}" >                                       
                                                    </h:outputLabel>
                                                </h:panelGroup>
                                            </p:column>     
                                            <p:column >
                                                <p:commandButton value="Update" ajax="false"  
                                                                action="#{surgeryBillController.updateTimedService(ti.billFee)}"
                                                                 disabled="#{ti.billFee.id eq null or surgeryBillController.batchBill.patientEncounter.paymentFinalized}"/>                                                                    
                                            </p:column>
                                            <p:column headerText="Remove">
                                                <p:commandButton ajax="false" value="Remove A"  
                                                                 rendered="#{ti.billFee.id eq null}"
                                                                action="#{surgeryBillController.removeTimedEncFromList(ti)}"
                                                                 disabled="#{surgeryBillController.batchBill.patientEncounter.paymentFinalized}"/>
                                                <p:commandButton ajax="false" value="Remove B"  
                                                                 rendered="#{ti.billFee.id ne null}"
                                                                action="#{surgeryBillController.removeTimedEncFromDbase(ti)}"
                                                                 disabled="#{surgeryBillController.batchBill.patientEncounter.paymentFinalized}"/>
                                            </p:column>
                                        </p:dataTable>
                                    </p:panel>
                                </h:panelGrid>
                            </p:panel>
                        </p:tab>
                    </p:tabView>

                </p:panel>           
            </h:form>
        </h:panelGroup>
    </ui:define>
</ui:composition>
